# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=utf8cpp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.2.3
pkgrel=1
pkgdesc="UTF-8 with C++ in a Portable Way (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/nemtrif/utfcpp"
license=(custom:BSL)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('3ba9b0dbbff08767bdffe8f03b10e596ca351228862722e4c9d4d126d2865250')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DUTF8_SAMPLES=OFF \
    -DUTF8_TESTS=OFF \
    ../${_realname/8}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 "${srcdir}"/${_realname/8}-${pkgver}/LICENSE -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/
}
